package org.myminidao.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class PackageUtil {
	public static List<String> getPackageClass(String packagePath, List<String> classNames) {
		List<String> myClassName = new ArrayList<String>();
		File file = new File(packagePath);
		File[] childFiles = file.listFiles();
		for (int i = 0; i < childFiles.length; i++) {
			File childFile = childFiles[i];
			if (childFile.isDirectory()) {
				myClassName.addAll(getPackageClass(childFile.getPath(), myClassName));
			} else {
				String childFilePath = childFile.getPath();
				childFilePath = childFilePath.substring(childFilePath.indexOf("\\classes") + 9, childFilePath.lastIndexOf("."));
				childFilePath = childFilePath.replaceAll("\\\\", ".");
				myClassName.add(childFilePath);
			}
		}
		
		return myClassName;
	}
	
	public static void main(String[] args) {
		String filePath = ClassLoader.getSystemResource("").getPath() + "com".replace(".", "\\");
		List<String> list = getPackageClass(filePath, null);
		for (String string : list) {
			System.out.println(string);
		}
	}
}
